package com.chen.service;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
*@Description: 实现三天免登陆
*@Param: * @param null
*@return:
*@Author: peanut
*@date 2019/6/2 17:38
*/
/* name 不知道是啥  urlPatterns 是访问名 */
@WebServlet(name = "hehe",urlPatterns = "/hehe")
public class Servlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp)   {
        try {
            /*设置请求格式和相应格式*/
            req.setCharacterEncoding("UTF-8");
            resp.setContentType("text/html;charset=UTF-8");
            /*处理请求*/
            Cookie[] cookies = req.getCookies();
            req.getRequestDispatcher("login").forward(req,resp);
            if (cookies!=null){
                /*不是第一次登陆有cookie*/
            }else {
                /*是第一次登陆无cookie*/
                    resp.getWriter().write("没有cookie信息");
            }
            String userName = req.getParameter("userName");
            String passWord = req.getParameter("passWord");
            System.out.println("用户名：" + userName + ",密码：" + passWord);
            /*返回给浏览器的信息*/
            resp.getWriter().write("我轻轻的来就像我轻轻的去不带走一片云彩，用户："+userName+"欢迎你O(∩_∩)O哈哈~");
        } catch (Exception e) {

            e.printStackTrace();
        }

    }
}
